﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DQYT.HTDZ.BLL;
using DQYT.HTDZ.Model;
using System.Data;
using DQYT.HTDZ.Common;
using System.Web.Services;


namespace SkWeb.FYCS
{
    public partial class TB_DJSKCBDNEW1 : System.Web.UI.Page
    {
        #region 事件处理程序

        //页面加载程序
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //AspNetPager1.Visible = true;
                lblPatd.Text = "费用预算 >> 单井射孔成本";
                BindJH();
                InitData();
                BindQX();
                BindDX();
                BindCLLTF();
                BindSGFS();
                BindZYLQX();
                BindJSLX();
                txtSJRQ.Value = DateTime.Now.Date.ToString("yyyy-MM-dd");
            }
            lblMsg.Text = "";
        }

        //井号列表选择事件
        protected void lbxJH_SelectedIndexChanged(object sender, EventArgs e)
        {
            //获取井号ID
            //string ID = this.lbxJH.SelectedValue;
            ////获取井号
            //string JH = this.lbxJH.SelectedItem.Text;
            //txtSJRQ.Value = DateTime.Now.Date.ToString("yyyy-MM-dd");
            //hidId.Value = this.lbxJH.SelectedValue.ToString();
            InitData();
            lblMsg.Text = "";
        }

        /// <summary>
        /// 备注:分页事件
        /// 时间:2012年11月6日 23:30:12
        /// 作者:jiejiep
        /// </summary>
        protected virtual void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            BindJH();
        }

        //添加按钮点击事件
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            Save();
        }

        //查询按钮点击事件
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            //if (!string.IsNullOrEmpty(this.txtName.Text.Trim()))
            //{
            //    string where = @"JH like'%" + this.txtName.Text.Trim() + "%'";
            //    PageInfo pageinfo = new PageInfo();
            //    //pageinfo.PageSize = this.AspNetPager1.PageSize;
            //    //pageinfo.PageIndex = this.AspNetPager1.CurrentPageIndex;
            //    SkgysjbBLL BLL = new SkgysjbBLL();
            //    DataTable dt = BLL.GetListByPage(where, pageinfo.PageIndex, pageinfo.PageSize).Tables[0];
            //    //this.lbxJH.DataSource = dt;
            //    //this.lbxJH.DataBind();
            //    //this.AspNetPager1.RecordCount = pageinfo.RecordCount;
            //}
            //else
            //{
            //    PageInfo pageinfo = new PageInfo();
            //    //pageinfo.PageSize = this.AspNetPager1.PageSize;
            //    //pageinfo.PageIndex = this.AspNetPager1.CurrentPageIndex;
            //    SkgysjbBLL BLL = new SkgysjbBLL();
            //    DataTable dt = BLL.GetListByPage("", pageinfo.PageIndex, pageinfo.PageSize).Tables[0];
            //    //this.lbxJH.DataSource = dt;
            //    //this.lbxJH.DataBind();
            //    //this.AspNetPager1.RecordCount = pageinfo.RecordCount;
            //}
        }

        //弹型选择事件
        protected void ddlstDX_SelectedIndexChanged(object sender, EventArgs e)
        {
            string DXID = this.ddlst_DX.SelectedValue.Trim();
            TB_SKJSBLL bll = new TB_SKJSBLL();
            TB_SKJSInfo model = bll.GetModel(int.Parse(DXID));
            //hidJG.Value = model.JG.ToString();
            string XL = model.SK_XM_XL.Trim();
            string QX = this.ddlst_DX.SelectedItem.Text;
            XL = XL.Substring(0, 2);
            int L = QX.IndexOf("(");
            int R = QX.IndexOf(")");
            if (L > 0 && R > 0)
            {
                QX = QX.Substring(L + 1, R - L - 1);
            }
            else
            {
                QX = "普通";
            }
            //txtSGFS.Text = QX + XL;
            //弹型
            string DX = ddlst_DX.SelectedItem.Text;
            int L1 = DX.IndexOf("/");
            if (L1 >= 0)
            {
                DX = DX.Substring(L1 + 1);
                int L2 = DX.IndexOf("/");
                if (L2 >= 0)
                {
                    DX = DX.Substring(L2 + 1);
                    int L3 = QX.IndexOf("(");
                    int R3 = QX.IndexOf(")");
                    if (L3 >= 0 && R3 >= 0)
                    {
                        DX = DX.Substring(L3 + 1, R3 - L3 - 1);
                    }
                }
            }
            else
            {
                DX = "";
            }
            //项目
            txtXM.Text = DX + ddlst_QX.Text + txt_FHLX.Text;
        }

        //枪型2下拉框选择事件
        protected void ddlst_ZYLQX_SelectedIndexChanged(object sender, EventArgs e)
        {
            string DX = ddlst_DX.SelectedItem.Text.Trim();
            string QX = ddlst_QX.SelectedItem.Text.Trim();
            string QX2 = ddlst_ZYLQX.SelectedItem.Text.Trim();
            TB_QDJBLL qdjbll = new TB_QDJBLL();
            DataTable dt = qdjbll.GetList(" DX = '" + DX + "' AND QX = '" + QX + "' AND ZYLQX='" + QX2 + "'").Tables[0];
            string DDJ = string.Empty;
            string QDJ = string.Empty;
            if (dt.Rows.Count > 0)
            {
                DDJ = dt.Rows[0]["DDJ"].ToString();
                QDJ = dt.Rows[0]["QDJ"].ToString();

            }
            txtDDJ.Text = DDJ;
            txtQDJ.Text = QDJ;
        }

        //枪型选择事件
        protected void ddlst_QX_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.ddlst_ZYLQX.Items.Clear();
            TB_QDJBLL bll = new TB_QDJBLL();
            DataTable dt = bll.GetList(" QX = '" + ddlst_QX.SelectedItem.Text.Trim() + "'").Tables[0];
            this.ddlst_ZYLQX.Items.Add("");
            ddlst_ZYLQX.DataSource = dt;
            ddlst_ZYLQX.DataBind();
        }

        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.DropDownList2.Items.Clear();
            TB_QDJBLL bll = new TB_QDJBLL();
            DataTable dt = bll.GetList(" QX = '" + DropDownList1.SelectedItem.Text.Trim() + "'").Tables[0];
            this.DropDownList2.Items.Add("");
            DropDownList2.DataSource = dt;
            DropDownList2.DataBind();
        }
        //施工方式对比侧
        protected void DropDownList4_SelectedIndexChanged(object sender, EventArgs e)
        {
            string DX = DropDownList3.SelectedItem.Text.Trim();
            string QX = DropDownList1.SelectedItem.Text.Trim();
            string QX2 = DropDownList2.SelectedItem.Text.Trim();
            TB_QDJBLL qdjbll = new TB_QDJBLL();
            DataTable dt = qdjbll.GetList(" DX = '" + DX + "' AND QX = '" + QX + "' AND ZYLQX='" + QX2 + "'").Tables[0];
            string DDJ = string.Empty;
            string QDJ = string.Empty;
            if (dt.Rows.Count > 0)
            {
                DDJ = dt.Rows[0]["DDJ"].ToString();
                QDJ = dt.Rows[0]["QDJ"].ToString();

            }
            txtDDJDB.Text = DDJ;
            txtQDJDB.Text = QDJ;

            string LX = txt_LX.Text.Trim();
            string SGFS = DropDownList4.SelectedItem.Text.Trim();
            string JG = string.Empty;
            TB_SKJSBLL skjbbll = new TB_SKJSBLL();
            DataTable dt1 = skjbbll.GetList(" SK_FS ='" + QX + "' AND SK_XM='" + DX + "' AND SK_XM_XL ='" + LX + "' AND SK_XM_MX='" + SGFS + "'").Tables[0];
            if (dt1.Rows.Count > 0)
            {
                JG = dt1.Rows[0]["JG"].ToString();
            }
            if (!string.IsNullOrEmpty(JG))
            {
                double skhd = Convert.ToDouble(txt_SKHD.Text.Trim());
                double jg1 = Convert.ToDouble(JG);
                double clltf = Convert.ToDouble(ddlst_CLLTF.SelectedValue.Trim());
                txtDJSRDB.Text = (skhd * jg1 + clltf).ToString();
            }
        }
        //施工方式选择事件
        protected void ddlst_SGFS_SelectedIndexChanged(object sender, EventArgs e)
        {
            string QX = ddlst_QX.SelectedItem.Text.Trim();
            string DX = ddlst_DX.SelectedItem.Text.Trim();
            string LX = txt_LX.Text.Trim();
            string SGFS = ddlst_SGFS.SelectedItem.Text.Trim();
            string JG = string.Empty;
            TB_SKJSBLL skjbbll = new TB_SKJSBLL();
            DataTable dt = skjbbll.GetList(" SK_FS ='" + QX + "' AND SK_XM='" + DX + "' AND SK_XM_XL ='" + LX + "' AND SK_XM_MX='" + SGFS + "'").Tables[0];
            if (dt.Rows.Count > 0)
            {
                JG = dt.Rows[0]["JG"].ToString();
            }
            if (!string.IsNullOrEmpty(JG))
            {
                double skhd = Convert.ToDouble(txt_SKHD.Text.Trim());
                double jg1 = Convert.ToDouble(JG);

                txtDJSR.Text = (skhd * jg1).ToString();
                if (!string.IsNullOrEmpty(ddlst_CLLTF.SelectedValue.Trim()))
                {
                    double clltf = Convert.ToDouble(ddlst_CLLTF.SelectedValue.Trim());
                    double DJSR = 0;
                    if (!string.IsNullOrEmpty(txtDJSR.Text.Trim()))
                    {
                        DJSR = Convert.ToDouble(txtDJSR.Text.Trim());
                        txtDJSR.Text = (clltf + DJSR).ToString();
                    }
                }
                else
                {
                    double clltf = 0;
                    double DJSR = 0;
                    if (!string.IsNullOrEmpty(txtDJSR.Text.Trim()))
                    {
                        DJSR = Convert.ToDouble(txtDJSR.Text.Trim());
                        txtDJSR.Text = (clltf + DJSR).ToString();
                    }
                }

            }

        }

        //对比弹型
        protected void DropDownList3_SelectedIndexChanged1(object sender, EventArgs e)
        {
            string DX = DropDownList3.SelectedItem.Text.Trim();
            string QX = DropDownList1.SelectedItem.Text.Trim();
            string QX2 = DropDownList2.SelectedItem.Text.Trim();
            TB_QDJBLL qdjbll = new TB_QDJBLL();
            DataTable dt = qdjbll.GetList(" DX = '" + DX + "' AND QX = '" + QX + "' AND ZYLQX='" + QX2 + "'").Tables[0];
            string DDJ = string.Empty;
            string QDJ = string.Empty;
            if (dt.Rows.Count > 0)
            {
                DDJ = dt.Rows[0]["DDJ"].ToString();
                QDJ = dt.Rows[0]["QDJ"].ToString();

            }
            txtDDJDB.Text = DDJ;
            txtQDJDB.Text = QDJ;

            string LX = txt_LX.Text.Trim();
            string SGFS = ddlst_SGFS.SelectedItem.Text.Trim();
            string JG = string.Empty;
            TB_SKJSBLL skjbbll = new TB_SKJSBLL();
            DataTable dt1 = skjbbll.GetList(" SK_FS ='" + QX + "' AND SK_XM='" + DX + "' AND SK_XM_XL ='" + LX + "' AND SK_XM_MX='" + SGFS + "'").Tables[0];
            if (dt1.Rows.Count > 0)
            {
                JG = dt1.Rows[0]["JG"].ToString();
            }
            if (!string.IsNullOrEmpty(JG))
            {
                double skhd = Convert.ToDouble(txt_SKHD.Text.Trim());
                double jg1 = Convert.ToDouble(JG);
                double clltf = Convert.ToDouble(ddlst_CLLTF.SelectedValue.Trim());
                txtDJSRDB.Text = (skhd * jg1 + clltf).ToString();
            }
        }

        //车辆路途费
        protected void ddlst_CLLTF_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(ddlst_CLLTF.SelectedValue.Trim()))
            {
                double clltf = Convert.ToDouble(ddlst_CLLTF.SelectedValue.Trim());
                double DJSR = 0;
                if (!string.IsNullOrEmpty(txtDJSR.Text.Trim()))
                {
                    DJSR = Convert.ToDouble(txtDJSR.Text.Trim());
                    txtDJSR.Text = (clltf + DJSR).ToString();
                }
            }
            else
            {
                double clltf = 0;
                double DJSR = 0;
                if (!string.IsNullOrEmpty(txtDJSR.Text.Trim()))
                {
                    DJSR = Convert.ToDouble(txtDJSR.Text.Trim());
                    txtDJSR.Text = (clltf + DJSR).ToString();
                }
            }
        }

        //数据对比按钮点击事件
        protected void brn_DB_Click(object sender, EventArgs e)
        {
            //弹数对比
            txtDSDB.Text = txtDS.Text.Trim();
            double ds = 0;
            double ddj = 0;
            if (!string.IsNullOrEmpty(txtDSDB.Text.Trim()))
            {
                ds = Convert.ToDouble(txtDSDB.Text.Trim());
            }
            if (!string.IsNullOrEmpty(txtDDJDB.Text.Trim()))
            {
                ddj = Convert.ToDouble(txtDDJDB.Text.Trim());
            }
            txtDJEDB.Text = (ds * ddj).ToString();
            txtDJESJDB.Text = (ds * ddj).ToString();



            //枪长
            txtQCDB.Text = txtQC.Text.Trim();
            double qc = 0;
            double qdj = 0;
            if (!string.IsNullOrEmpty(txtQCDB.Text.Trim()))
            {
                qc = Convert.ToDouble(txtQCDB.Text.Trim());
            }
            if (!string.IsNullOrEmpty(txtQDJDB.Text.Trim()))
            {
                qdj = Convert.ToDouble(txtQDJDB.Text.Trim());
            }
            //枪长2对比
            txtQC2DB.Text = txtQC2.Text.Trim();
            //枪单价2对比
            txtQDJ2DB.Text = txtQDJ2.Text.Trim();
            double qc2 = 0;
            double qdj2 = 0;
            if (!string.IsNullOrEmpty(txtQC2DB.Text.Trim()))
            {
                qc2 = Convert.ToDouble(txtQC2DB.Text.Trim());
            }
            if (!string.IsNullOrEmpty(txtQDJ2DB.Text.Trim()))
            {
                qdj2 = Convert.ToDouble(txtQDJ2DB.Text.Trim());
            }
            txtQJEDB.Text = (Convert.ToDouble(qc * qdj) + Convert.ToDouble(qc2 * qdj2)).ToString();
            txtQJESZDB.Text = (Convert.ToDouble(qc * qdj) + Convert.ToDouble(qc2 * qdj2)).ToString();

            //夹层枪长
            txtJCQCDB.Text = txtJCQC.Text.Trim();
            //夹层枪单价
            txtJCQDJDB.Text = txtJCQDJ.Text.Trim();
            double jcqc = 0;
            double jcqdj = 0;
            if (!string.IsNullOrEmpty(txtJCQCDB.Text.Trim()))
            {
                jcqc = Convert.ToDouble(txtJCQCDB.Text.Trim());
            }
            if (!string.IsNullOrEmpty(txtJCQDJDB.Text.Trim()))
            {
                jcqdj = Convert.ToDouble(txtJCQDJDB.Text.Trim());
            }
            txtJCQJEDB.Text = (jcqc * jcqdj).ToString();
            txtJCQJESZDB.Text = (jcqc * jcqdj).ToString();

            //枪弹合计金额
            double qje = 0;
            double jcqje = 0;
            double dje = 0;
            if (!string.IsNullOrEmpty(txtQJEDB.Text.Trim()))
            {
                qje = Convert.ToDouble(txtQJEDB.Text.Trim());
            }
            if (!string.IsNullOrEmpty(txtJCQJEDB.Text.Trim()))
            {
                jcqje = Convert.ToDouble(txtJCQJEDB.Text.Trim());
            }
            if (!string.IsNullOrEmpty(txtDJEDB.Text.Trim()))
            {
                dje = Convert.ToDouble(txtDJEDB.Text.Trim());
            }
            txtQDHJJEDB.Text = (qje + jcqje + dje).ToString();
            //爆炸器材单价消耗
            txtBZQCDJXHDB.Text = txtBZQCDJXH.Text.Trim();
            //一般材料单价消耗
            txtYBCLDJXHDB.Text = txtYBCLDJXH.Text.Trim();
            double ybcldjxh = 0;
            double sgfsj = 0;
            if (!string.IsNullOrEmpty(txtYBCLDJXHDB.Text.Trim()))
            {
                ybcldjxh = Convert.ToDouble(txtYBCLDJXHDB.Text.Trim());
            }
            string sgfs = DropDownList4.SelectedItem.Text;
            if (sgfs.Equals("复合管输"))
            {
                sgfsj = 2120.92;
            }

            //平摊一般材料
            txtPTYBCLDB.Text = (ybcldjxh + sgfsj).ToString();

            double qdhjle = 0;
            double bzqcdjxh = 0;
            double ptybcl = 0;
            if (!string.IsNullOrEmpty(txtQDHJJEDB.Text.Trim()))
            {
                qdhjle = Convert.ToDouble(txtQDHJJEDB.Text.Trim());
            }
            if (!string.IsNullOrEmpty(txtBZQCDJXHDB.Text.Trim()))
            {
                bzqcdjxh = Convert.ToDouble(txtBZQCDJXHDB.Text.Trim());
            }
            if (!string.IsNullOrEmpty(txtPTYBCLDB.Text.Trim()))
            {
                ptybcl = Convert.ToDouble(txtPTYBCLDB.Text.Trim());
            }

            //单井材料成本
            txtDJCLCBDB.Text = (qdhjle + bzqcdjxh + ptybcl).ToString();

            //单井成本
            //单井材料成本
            double DJCLCB = 0;
            if (!string.IsNullOrEmpty(txtDJCLCBDB.Text.Trim()))
            {
                DJCLCB = Convert.ToDouble(txtDJCLCBDB.Text.Trim());
            }
            //固定费用
            double GDFY = 0;
            if (!string.IsNullOrEmpty(txtGDFY.Text.Trim()))
            {
                GDFY = Convert.ToDouble(txtGDFY.Text.Trim());
            }
            //折旧费
            double ZJF = 0;
            if (!string.IsNullOrEmpty(txtZJF.Text.Trim()))
            {
                ZJF = Convert.ToDouble(txtZJF.Text.Trim());
            }
            //其他变动费用
            double QTBDFY = 0;
            if (!string.IsNullOrEmpty(txtQTBDFY.Text.Trim()))
            {
                QTBDFY = Convert.ToDouble(txtQTBDFY.Text.Trim());
            }
            txtDJCBDB.Text = (DJCLCB + GDFY + ZJF + QTBDFY).ToString();

            //单井收入
            double DJSR = 0;
            if (!string.IsNullOrEmpty(txtDJSRDB.Text.Trim()))
            {
                DJSR = Convert.ToDouble(txtDJSRDB.Text.Trim());
            }
            //单井成本
            double DJCB = 0;
            if (!string.IsNullOrEmpty(txtDJCBDB.Text.Trim()))
            {
                DJCB = Convert.ToDouble(txtDJCBDB.Text.Trim());
            }

            txtYYDB.Text = (DJSR - DJCB).ToString();
        }


        protected void btnRefresh_Click(object sender, EventArgs e)
        {
            InitData();
        }

        #endregion 事件处理程序

        #region 函数集

        /// <summary>
        /// 绑定结算类型
        /// </summary>
        public void BindJSLX()
        {
            TB_JSLXBLL bll = new TB_JSLXBLL();
            ddlstJSLX.DataSource = bll.GetList("").Tables[0];
            ddlstJSLX.DataBind();
        }

        /// <summary>
        /// 绑定周艳丽枪型
        /// </summary>
        public void BindZYLQX()
        {
            TB_QDJBLL bll = new TB_QDJBLL();
            DataTable dt = bll.GetList("").Tables[0];
            this.ddlst_ZYLQX.Items.Add("");
            ddlst_ZYLQX.DataSource = dt;
            ddlst_ZYLQX.DataBind();
            DropDownList2.DataSource = dt;
            DropDownList2.DataBind();
        }

        /// <summary>
        /// 绑定施工方式
        /// </summary>
        public void BindSGFS()
        {
            TB_SGFSBLL bll = new TB_SGFSBLL();

            DataTable dt = bll.GetList("").Tables[0];
            this.ddlst_SGFS.Items.Add("");
            ddlst_SGFS.DataSource = dt;
            ddlst_SGFS.DataBind();
            DropDownList4.Items.Add("");
            DropDownList4.DataSource = dt;
            DropDownList4.DataBind();
        }

        /// <summary>
        /// 绑定车辆路途费
        /// </summary>
        public void BindCLLTF()
        {
            TB_CLLTFBLL bll = new TB_CLLTFBLL();

            DataTable dt = bll.GetList("").Tables[0];
            this.ddlst_CLLTF.Items.Add("");
            ddlst_CLLTF.DataSource = dt;
            ddlst_CLLTF.DataBind();
        }

        /// <summary>
        /// 绑定弹型
        /// </summary>
        public void BindDX()
        {
            TB_DDJBLL bll = new TB_DDJBLL();

            DataTable dt = bll.GetList("").Tables[0];
            this.ddlst_DX.Items.Add("");
            ddlst_DX.DataSource = dt;
            ddlst_DX.DataBind();
            DropDownList3.DataSource = dt;
            DropDownList3.DataBind();
        }

        /// <summary>
        /// 绑定枪型
        /// </summary>
        public void BindQX()
        {
            TB_QDJBLL bll = new TB_QDJBLL();

            DataTable dt = bll.GetList("").Tables[0];
            this.ddlst_QX.Items.Add("");
            ddlst_QX.DataSource = dt;
            ddlst_QX.DataBind();
            DropDownList1.DataSource = dt;
            DropDownList1.DataBind();
        }

        /// <summary>
        /// 保存数据函数
        /// </summary>
        public void Save()
        {
            try
            {
                TB_DJSKCBBLL bll = new TB_DJSKCBBLL();
                TB_DJSKCBInfo model = new TB_DJSKCBInfo();
                model.ID = Convert.ToInt32(txtID.Value.Trim());
                model.JH = txtJH.Text.Trim();
                if (!txtSJRQ.Value.Trim().Equals(string.Empty)) model.SJRQ = Convert.ToDateTime(txtSJRQ.Value.Trim());
                model.SGFS = ddlst_SGFS.Text.Trim();
                model.LX = txt_LX.Text.Trim();
                if (!txtJS.Text.Trim().Equals(string.Empty)) model.JS = Convert.ToInt32(txtJS.Text.Trim());
                model.XM = txtXM.Text.Trim();
                model.DX = ddlst_DX.SelectedItem.Text.Trim();
                model.QX = ddlst_QX.Text.Trim();
                model.ZYLQX = ddlst_ZYLQX.Text.Trim();
                model.FHLX = txt_FHLX.Text.Trim();
                model.JSLX = ddlstJSLX.SelectedValue.Trim();
                if (!Request.Form["txtDJSR"].Trim().Equals(string.Empty)) model.DJSR = Convert.ToDecimal(Request.Form["txtDJSR"].Trim());
                if (!txt_SKHD.Text.Trim().Equals(string.Empty)) model.SKHD = Convert.ToDecimal(txt_SKHD.Text.Trim());
                if (!txtDS.Text.Trim().Equals(string.Empty)) model.DS = Convert.ToInt32(txtDS.Text.Trim());
                if (!txtDDJ.Text.Trim().Equals(string.Empty)) model.DDJ = Convert.ToDecimal(txtDDJ.Text.Trim());
                if (!Request.Form["txtDJE"].Trim().Equals(string.Empty)) model.DJE = Convert.ToDecimal(Request.Form["txtDJE"].Trim());
                if (!Request.Form["txtDJESZ"].Trim().Equals(string.Empty)) model.DJESZ = Convert.ToDecimal(Request.Form["txtDJESZ"].Trim());
                if (!txtQC.Text.Trim().Equals(string.Empty)) model.QC = Convert.ToDecimal(txtQC.Text.Trim());
                if (!txtQDJ.Text.Trim().Equals(string.Empty)) model.QDJ = Convert.ToDecimal(txtQDJ.Text.Trim());
                if (!txtQC2.Text.Trim().Equals(string.Empty)) model.QC2 = Convert.ToDecimal(txtQC2.Text.Trim());
                if (!txtQDJ2.Text.Trim().Equals(string.Empty)) model.QDJ2 = Convert.ToDecimal(txtQDJ2.Text.Trim());
                if (!Request.Form["txtQJE"].Trim().Equals(string.Empty)) model.QJE = Convert.ToDecimal(Request.Form["txtQJE"].Trim());
                if (!Request.Form["txtQJESZ"].Trim().Equals(string.Empty)) model.QJESZ = Convert.ToDecimal(Request.Form["txtQJESZ"].Trim());
                if (!txtJCQC.Text.Trim().Equals(string.Empty)) model.JCQC = Convert.ToDecimal(txtJCQC.Text.Trim());
                if (!txtJCQDJ.Text.Trim().Equals(string.Empty)) model.JCQDJ = Convert.ToDecimal(txtJCQDJ.Text.Trim());
                if (!Request.Form["txtJCQJE"].Trim().Equals(string.Empty)) model.JCQJE = Convert.ToDecimal(Request.Form["txtJCQJE"].Trim());
                if (!Request.Form["txtQDHJJE"].Trim().Equals(string.Empty)) model.QDHJJE = Convert.ToDecimal(Request.Form["txtQDHJJE"].Trim());
                if (!Request.Form["txtJCQJESZ"].Trim().Equals(string.Empty)) model.JCQJESZ = Convert.ToDecimal(Request.Form["txtJCQJESZ"].Trim());
                if (!txtBZQCDJXH.Text.Trim().Equals(string.Empty)) model.BZQCDJXH = Convert.ToDecimal(txtBZQCDJXH.Text.Trim());
                if (!txtYBCLDJXH.Text.Trim().Equals(string.Empty)) model.YBCLDJXH = Convert.ToDecimal(txtYBCLDJXH.Text.Trim());
                if (!Request.Form["txtPTYBCL"].Trim().Equals(string.Empty)) model.PTYBCL = Convert.ToDecimal(Request.Form["txtPTYBCL"].Trim());
                if (!Request.Form["txtDJCLCB"].Trim().Equals(string.Empty)) model.DJCLCB = Convert.ToDecimal(Request.Form["txtDJCLCB"].Trim());
                if (!txtGDFY.Text.Trim().Equals(string.Empty)) model.GDFY = Convert.ToDecimal(txtGDFY.Text.Trim());
                if (!txtZJF.Text.Trim().Equals(string.Empty)) model.ZJF = Convert.ToDecimal(txtZJF.Text.Trim());
                if (!txtQTBDFY.Text.Trim().Equals(string.Empty)) model.QTBDFY = Convert.ToDecimal(txtQTBDFY.Text.Trim());
                if (!Request.Form["txtDJCB"].Trim().Equals(string.Empty)) model.DJCB = Convert.ToDecimal(Request.Form["txtDJCB"].Trim());
                if (!Request.Form["txtYY"].Trim().Equals(string.Empty)) model.YY = Convert.ToDecimal(Request.Form["txtYY"].Trim());
                if (!txtJDDS.Text.Trim().Equals(string.Empty)) model.JDDS = Convert.ToDecimal(txtJDDS.Text.Trim());
                if (!txtJDDS1.Text.Trim().Equals(string.Empty)) model.JDDS1 = Convert.ToDecimal(txtJDDS1.Text.Trim());
                if (!txtJD.Text.Trim().Equals(string.Empty)) model.JD = Convert.ToDecimal(txtJD.Text.Trim());
                if (!txtJDSK.Text.Trim().Equals(string.Empty)) model.JDSK = Convert.ToDecimal(txtJDSK.Text.Trim());
                if (!txt_SKHD.Text.Trim().Equals(string.Empty)) model.SKHD2 = Convert.ToDecimal(txt_SKHD.Text.Trim());
                if (!ddlst_CLLTF.SelectedValue.Trim().Equals(string.Empty)) model.CLLTF = Convert.ToDecimal(ddlst_CLLTF.SelectedValue.Trim());
                string where = @" JH='" + txtJH.Text.Trim() + "'";
                string ID = string.Empty;
                DataSet ds = bll.GetList(where);
                if (ds != null && ds.Tables.Count >= 0 && ds.Tables[0].Rows.Count > 0)
                {
                    ID = ds.Tables[0].Rows[0]["ID"].ToString();
                }

                //修改
                if (!string.IsNullOrEmpty(ID))
                {
                    if (!bll.Update(model).Equals("0"))
                    {
                        lblMsg.Text = "修改成功";
                        InitData();
                    }
                }
                //添加
                else
                {
                    if (!bll.Add(model).Equals("0"))
                    {
                        lblMsg.Text = "添加成功";
                        InitData();
                    }
                }
            }


            catch (Exception ex)
            {
                lblMsg.Text = ex.Message;
            }
        }
      
        //页面加载方法
        public void InitData()
        {
            TB_DJSKCBBLL bll = new TB_DJSKCBBLL();
            TB_DJSKCBInfo model = new TB_DJSKCBInfo();
            SkgysjbBLL skBLL = new SkgysjbBLL();
            SkgysjbModel skModel = new SkgysjbModel();
            string ID = hidId.Value.Trim();
            // 获得主键参数
            if (!string.IsNullOrEmpty(ID))
            {
                model = bll.GetModel(int.Parse(ID));
                skModel = skBLL.GetModel(int.Parse(ID));
                txtID.Value = hidId.Value;
                txtJH.Text = skModel.JH;
                txtSJRQ.Value = model.SJRQ == Convert.ToDateTime("1900-1-1") ? DateTime.Now.Date.ToString("yyyy-MM-dd") : model.SJRQ.ToString();
                if (!string.IsNullOrEmpty(model.SGFS))
                {
                    ddlst_SGFS.SelectedValue = model.SGFS.ToString();
                }
                else
                {
                    //ddlst_SGFS.SelectedValue = "";
                }
                if (!string.IsNullOrEmpty(model.LX))
                    txt_LX.Text = model.LX.ToString();
                else
                    txt_LX.Text = skModel.SGLX;
                txtJS.Text = model.JS == int.MinValue ? "0" : model.JS.ToString();

                if (!string.IsNullOrEmpty(model.DX))
                    ddlst_DX.SelectedItem.Text = model.DX.ToString();
                else
                    ddlst_DX.SelectedItem.Text = skModel.SKDX;
                if (!string.IsNullOrEmpty(model.QX))
                    ddlst_QX.SelectedItem.Text = model.QX.ToString();
                else
                    ddlst_QX.SelectedItem.Text = skModel.SKQX;
                if (!string.IsNullOrEmpty(model.ZYLQX))
                    ddlst_ZYLQX.SelectedItem.Text = model.ZYLQX.ToString();
                else
                    //ddlst_ZYLQX.SelectedItem.Text = "";
                    if (!string.IsNullOrEmpty(model.FHLX))
                        txt_FHLX.Text = model.FHLX.ToString();
                    else
                        txt_FHLX.Text = skModel.TSSGLX;
                if (!string.IsNullOrEmpty(model.XM))
                    txtXM.Text = model.XM.ToString();
                else
                {
                    string DX1 = ddlst_DX.SelectedItem.Text.Trim();
                    string QX1 = ddlst_QX.SelectedItem.Text.Trim();
                    string FHLX1 = txt_FHLX.Text.Trim();

                    txtXM.Text = DX1 + QX1 + FHLX1;
                }
                if (!string.IsNullOrEmpty(model.JSLX))
                    ddlstJSLX.SelectedValue = model.JSLX.ToString();
                else
                    ddlstJSLX.SelectedValue = "";
                txtDJSR.Text = model.DJSR == int.MinValue ? string.Empty : model.DJSR.ToString();

                txt_SKHD.Text = model.SKHD == int.MinValue ? skModel.SKHD.ToString() : model.SKHD.ToString();


               txtDS.Text = model.DS == int.MinValue ? string.Empty : model.DS.ToString();

               txtDDJ.Text = model.DDJ == int.MinValue ? string.Empty : model.DDJ.ToString();
               txtQDJ.Text = model.QDJ == int.MinValue ? string.Empty : model.QDJ.ToString();


               txtDJE.Text = model.DJE == int.MinValue ? string.Empty : model.DJE.ToString();
               txtDJESZ.Text = model.DJESZ == int.MinValue ? string.Empty : model.DJESZ.ToString();
               txtQC.Text = model.QC == int.MinValue ? string.Empty : model.QC.ToString();
               txtQDJ.Text = model.QDJ == int.MinValue ? string.Empty : model.QDJ.ToString();
               txtQC2.Text = model.QC2 == int.MinValue ? string.Empty : model.QC2.ToString();
               txtQDJ2.Text = model.QDJ2 == int.MinValue ? string.Empty : model.QDJ2.ToString();
               txtQJE.Text = model.QJE == int.MinValue ? string.Empty : model.QJE.ToString();
               txtQJESZ.Text = model.QJESZ == int.MinValue ? string.Empty : model.QJESZ.ToString();
               txtJCQC.Text = model.JCQC == int.MinValue ? string.Empty : model.JCQC.ToString();
               txtJCQDJ.Text = model.JCQDJ == int.MinValue ? string.Empty : model.JCQDJ.ToString();
               txtJCQJE.Text = model.JCQJE == int.MinValue ? string.Empty : model.JCQJE.ToString();
               txtQDHJJE.Text = model.QDHJJE == int.MinValue ? string.Empty : model.QDHJJE.ToString();
               txtJCQJESZ.Text = model.JCQJESZ == int.MinValue ? string.Empty : model.JCQJESZ.ToString();
               txtBZQCDJXH.Text = model.BZQCDJXH == int.MinValue ? string.Empty : model.BZQCDJXH.ToString();
               txtYBCLDJXH.Text = model.YBCLDJXH == int.MinValue ? string.Empty : model.YBCLDJXH.ToString();
               txtPTYBCL.Text = model.PTYBCL == int.MinValue ? string.Empty : model.PTYBCL.ToString();
               txtDJCLCB.Text = model.DJCLCB == int.MinValue ? string.Empty : model.DJCLCB.ToString();
               txtGDFY.Text = model.GDFY == int.MinValue ? "11968.51" : model.GDFY.ToString();
               txtZJF.Text = model.ZJF == int.MinValue ? "1902.52" : model.ZJF.ToString();
               txtQTBDFY.Text = model.QTBDFY == int.MinValue ? "6643.32" : model.QTBDFY.ToString();
               txtDJCB.Text = model.DJCB == int.MinValue ? string.Empty : model.DJCB.ToString();
               txtYY.Text = model.YY == int.MinValue ? string.Empty : model.YY.ToString();

               txtJDDS.Text = model.JDDS == int.MinValue ? skModel.SKJD1.ToString() : model.JDDS.ToString();
               txtJDDS1.Text = model.JDDS1 == int.MinValue ? skModel.SKJD2.ToString() : model.JDDS1.ToString();

                double JDDS = 0;
                double JDDS1 = 0;
                double JD = 0;
                if (!string.IsNullOrEmpty(txtJDDS.Text.Trim()))
                    JDDS = Convert.ToDouble(txtJDDS.Text.Trim());
                if (!string.IsNullOrEmpty(txtJDDS1.Text.Trim()))
                    JDDS1 = Convert.ToDouble(txtJDDS1.Text.Trim());
                JD = JDDS - JDDS1;
                txtJD.Text = model.JD == int.MinValue ? JD.ToString() : model.JD.ToString();

                double SKHD = 0;
                double JDSK = 0;
                if (!string.IsNullOrEmpty(txt_SKHD.Text.Trim()))
                    SKHD = Convert.ToDouble(txt_SKHD.Text.Trim());
                JDSK = JD / SKHD;
                JDSK = Math.Round(JDSK, 2);
                txtJDSK.Text = model.JDSK == int.MinValue ? JDSK.ToString() : model.JDSK.ToString();

                string CB = skModel.CB;
                if (CB.IndexOf("一厂") != -1 || CB.IndexOf("二厂") != -1 || CB.IndexOf("三厂") != -1 || CB.IndexOf("四厂") != -1 || CB.IndexOf("五厂") != -1 || CB.IndexOf("六厂") != -1)
                {
                    ddlst_CLLTF.SelectedValue = model.CLLTF == int.MinValue ? "4200" : model.CLLTF.ToString();
                }
                else if (CB.IndexOf("七厂") != -1 || CB.IndexOf("八厂") != -1 || CB.IndexOf("九厂") != -1 || CB.IndexOf("十厂") != -1)
                {
                    ddlst_CLLTF.SelectedValue = model.CLLTF == int.MinValue ? "6600" : model.CLLTF.ToString();
                }
                //txt_SKHD.Text = model.SKHD2 == int.MinValue ? string.Empty : model.SKHD2.ToString();



            }
        }

        /// <summary>
        /// 绑定井号
        /// </summary>
        public void BindJH()
        {
            PageInfo pageinfo = new PageInfo();
            //pageinfo.PageSize = this.AspNetPager1.PageSize;
            //pageinfo.PageIndex = this.AspNetPager1.CurrentPageIndex;
            SkgysjbBLL BLL = new SkgysjbBLL();
            DataTable dt = BLL.GetListByPage("", pageinfo.PageIndex, pageinfo.PageSize).Tables[0];
            //this.lbxJH.DataSource = dt;
            //this.lbxJH.DataBind();
            //this.AspNetPager1.RecordCount = pageinfo.RecordCount;
        }

        #endregion 函数集 
    }
}